Passed
Push — master ( 622eb3...88f58b )
by Vinicius
01:47
created

index.ts ➔ pikaResolver   A

Complexity

Conditions 3

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 16
dl 0
loc 19
ccs 6
cts 6
cp 1
crap 3
rs 9.6
c 0
b 0
f 0
1 1
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
import { Plugin } from 'rollup'
3 1
import { getVersion } from './version'
4
5 1
const PIKA_CDN_HOST = 'https://cdn.pika.dev'
6
7
function pikaResolver ({ modules, cdnHost = PIKA_CDN_HOST }: { modules: string[], cdnHost: string }) {
8 1
  const cache = new Map<string, string>()
9
10 1
  return {
11
    name: 'pika-resolver',
12
    async resolveId (id: string) {
13 2
      if (!modules.includes(id)) {
14 1
        return id
15
      }
16
17 1
      const version = await getVersion(this, cache, id)
18
19 1
      return {
20
        id: `${cdnHost}/${version}`,
21
        external: true
22
      }
23
    }
24
  } as Plugin
25
}
26
27 1
export { pikaResolver }
28
export default pikaResolver
29